<template>
	<view class="main">
		<!-- 指数信息 -->
		<view class="main__index">
			<view :class="['index__item', item.zhangdiebaifenbi > 0 ?'index__item--add':'']" 
			v-for="(item, index) in marketIndexList" :key="index" >
				<view class="item__title">{{item.name}}</view>
				<view class="item__num">{{item.zhangdiebaifenbi | formatPercent}}</view>
			</view>
		</view>
		<!-- 榜单详情-->
		<view class="main__rank" v-if="false">
			<view class="rank__title">{{$t("market.rank")}}</view>
			<view class="rank__list">
				<view class="list__item" v-for="(item, index) in hotList" :key="index"  @click="itemClick(item)">
					<view class="item__title">{{item.name}}</view>
					<view class="item__num">{{item.zhangdiebaifenbi}}</view>
					<view class="item__info">
						<text class="info__num">{{item.zhangdiebaifenbi}}</text>
						<text class="info__num">{{item.zhangdieshu > 0 ? "+" + item.zhangdieshu : item.zhangdieshu}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 全部 -->
		<view class="main__all">
			<div class="all__title">
				<text class="title__text">{{$t("market.all")}}</text>
				<view class="title__more" @click="moreClick">
					<text class="more__text">{{$t("market.more")}}</text>
					<uni-icons type="right" color="#fff" size="16"></uni-icons>
				</view>
			</div>
			<view class="all__header">
				<view class="header__item">{{$t('stock.name')}}</view>
				<view class="header__item" @click="changePriceOlder">{{$t('stock.price')}}
					<image src="@/static/icons/order_icon.png" mode="widthFix" class="item__icon"></image>
				</view>
				<view class="header__item" @click="increaseClick">{{$t('stock.riseFall')}}
					<image src="@/static/icons/order_icon.png" mode="widthFix" class="item__icon"></image>
				</view>
			</view>
			<view :class="['all__item', item.zhangdiebaifenbi > 0 ?'all__item--add':'']" 
			v-for="(item, index) in marketList" :key="index"  @click="itemClick(item)">
				<view class="item__name">
					<view class="name__text">{{item.name}}</view>
					<view class="name__info">
						<!-- <text :class="['info__tag', 'info__tag--'+item.codeName]">{{item.codeName}}</text> -->
						<image :src="iconUrl" mode="aspectFill" class="info__icon"></image>
						<!-- <text v-if="item.category_id == 3" class="info__code">{{item.shuzidaima.toString().padStart(5, '0')}}</text>
						 -->
						<text class="info__code">{{item.shuzidaima}}</text>
					</view>
				</view>
				<view class="item__price">
					<view class="price__num">{{item.price | format}}</view>
					<!-- <text class="price__count">4.930</text> -->
				</view>
				<view class="item__increa">
					<text class="increa__num">{{item.zhangdiebaifenbi | formatPercent}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {}
		},
		props:{
			marketIndexList:{ //股票指数列表
				type:Array,
				default:()=>([])
			},
			marketList:{ // 市场股票列表
				type:Array,
				default:()=>([])
			},
			hotList:{ //市场热门榜单列表
				type:Array,
				default:()=>([])
			},
			cate:{
				type:Object,
				default:()=>({})
			},
		},
		computed:{
			iconUrl(){
				let file = this.cate.file  //KRN US HK
				return `/static/icons/${file}.png`
			}
		},
		filters:{
			// 格式化百分比
			formatPercent(float){
				let num = float ? float : 0
				return num.toFixed(2) + "%"
			},
			format(float){
				return float.toFixed(2)
			}
		},
		methods:{
			moreClick(){
				let {id,file} = this.cate
				uni.navigateTo({
					url:`/pages/market/marketList?id=${id}&file=${file}`
				})
			},
			itemClick(item){
				uni.navigateTo({
										url:`/pages/account/stockDetail?id=${item.id}&info=`+encodeURIComponent(JSON.stringify(item))

				})
			},
			// 切换价格排序
			changePriceOlder(){
				this.$emit("orderChange", 'zhangdieshu')
			},
			// 涨幅排序
			increaseClick(){
				this.$emit("orderChange", 'zhangdiebaifenbi')
			}
		},
		
	}
</script>

<style lang="scss" scoped>
	.main{
		margin-top: 30rpx;
		.main__index{
			margin-top: 34rpx;
			@include flexRowAlign();
			.index__item{
				width: 218rpx;
				height: 168rpx;
				background: rgba(#2DC065, 0.8);
				border-radius: 8rpx;
				padding: 20rpx 12rpx;
				box-sizing: border-box;
				margin-left: 30rpx;
				@include flexCenter(column);
				&:first-child{
					margin-left: 0;
				}
				.item__title{
					font-size: 28rpx;
					font-weight: bold;
					color: #FFFFFF;
				}
				.item__num{
					font-size: 32rpx;
					font-weight: 800;
					color: #fff;
					margin-top: 20rpx;
					text-align: center;
				}
				.item__info{
					margin-top: 6rpx;
					@include flexRowAlign(space-between);
					.info__num{
						font-size: 24rpx;
						color: #2DC065;
					}
				}
			}
			.index__item--add{
				background: rgba(#DF4140, 0.8);
				.item__num{
					color: #fff;
				}
				.item__info{
					.info__num{
						color: #DF4140;
					}
				}
			}
		}
		.main__rank{
			margin-top: 60rpx;
			.rank__title{
				font-size: 34rpx;
				font-weight: 800;
				color: #FFFFFF;
			}
			.rank__list{
				margin-top: 30rpx;
				@include flexRowAlign(space-between);
				overflow-x: scroll;
				.list__item{
					flex-shrink: 0;
					width: 218rpx;
					height: 196rpx;
					background: rgba(#fff, 0.1);
					border-radius: 8rpx;
					padding: 20rpx 12rpx;
					box-sizing: border-box;
					margin-right: 20rpx;
					&:last-child{
						margin-right: 0;
					}
					.item__title{
						font-size: 26rpx;
						font-weight: bold;
						color: #FFFFFF;
						width: 100%;
						@include textOver();
						height: 66rpx;
					}
					.item__num{
						font-size: 32rpx;
						font-weight: 800;
						color: #2DC065;
						margin-top: 12rpx;
					}
					.item__tag{
						font-size: 26rpx;
						color: #999999;
						margin-top: 14rpx;
					}
					.item__info{
						margin-top: 6rpx;
						@include flexRowAlign(space-between);
						.info__num{
							font-size: 24rpx;
							color: #2DC065;
						}
					}
				}
			}
		}
		.main__all{
			margin-top: 60rpx;
			.all__title{
				@include flexRowAlign(space-between);
				.title__text{
					font-size: 34rpx;
					font-weight: 800;
					color: #fff;
				}
				.title__more{
					@include flexRowAlign();
					font-size: 28rpx;
					color: #999999;
				}
			}
			.all__header{
				@include flexRowAlign(space-between);
				height: 64rpx;
				margin-top: 20rpx;
				.header__item{
					@include flexRowAlign(center);
					font-size: 28rpx;
					color: #999999;
					width: 220rpx;
					.item__icon{
						width: 24rpx;
						height: 28rpx;
						margin-left: 4rpx;
					}
					&:nth-child(2){
						flex: 1;
					}
					&:first-child{
						justify-content: flex-start;
					}
					&:last-child{
						flex: 1;
						justify-content: flex-end;
					}
				}
			}
			.all__item{
				@include flexRowAlign(space-between);
				height: 138rpx;
				// border-top: 1rpx solid #EEEEEE;
				.item__name{
					@include flexCenter(column);
					align-items: flex-start;
					.name__text{
						@include textOver();
						width: 220rpx;
						font-size: 28rpx;
						color: #fff;
					}
					.name__info{
						@include flexRowAlign()
						margin-top: 10rpx;
						.info__tag{
							color: #fff;
							font-size: 24rpx;
							height: 28rpx;
							background: #FF3B46;
							padding: 0 6rpx;
							border-radius: 6rpx;
							@include flexCenter();
						}
						.info__icon{
							width: 30rpx;
							height: 30rpx;
							border-radius: 50%;
						}
						.info__tag--US{
							background: #0369F6;
						}
						.info__tag--HK{
							background: #DE2804;
						}
						.info__code{
							color: #fff;
							font-size: 24rpx;
							margin-left: 10rpx;
						}
					}
				}
				.item__price{
					@include flexCenter(column);
					flex: 1;
					.price__num{
						font-size: 28rpx;
						font-weight: 800;
						color: #2DC065;
					}
					.price__count{
						font-size: 24rpx;
						font-weight: 500;
						color: #FFFFFF;
					}
				}
				.item__increa{
					@include flexRowAlign(flex-end);
					flex: 1;
					.increa__num{
						min-width: 150rpx;
						height: 48rpx;
						background: rgba(#2DC065, 0.5);
						border-radius: 8rpx;
						padding:  0 10rpx;
						@include flexCenter(column);
						font-size: 28rpx;
						font-weight: 800;
						color: #2DC065;
					}
				}
			}
			.all__item--add{
				.item__price{
					.price__num{
						color: #FF3B46;
					}
				}
				.item__increa{
					.increa__num{
						background: rgba(#FF3B46, 0.5);
						color: #FF3B46;
					}
				}
			}
		}
	}
</style>